package com.sdp.right.db.sys_entity_info.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.right.db.sys_entity_field.service.ISysEntityFieldService;
import com.sdp.right.db.sys_entity_info.mapper.SysEntityInfoMapper;
import com.sdp.right.db.sys_entity_info.service.ISysEntityInfoService;
import com.sdp.right.entity.SysEntityField;
import com.sdp.right.entity.SysEntityInfo;
import com.sdp.right.service.RemoveSystemService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2023-11-13
 */
@Service
@DS(value="right")
public class SysEntityInfoServiceImpl extends ServiceImpl<SysEntityInfoMapper, SysEntityInfo> implements ISysEntityInfoService,RemoveSystemService{

	@Autowired
	private ISysEntityFieldService iSysEntityFieldService;
	
	@Override
	public void removeSysEntityInfoByClassName(String className) {
		LambdaQueryWrapper<SysEntityInfo> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysEntityInfo::getEntityClassName, className);
		remove(queryWrapper);
		
	}

	@Override
	public void removeBySystemNo(String systemNo) {
		LambdaQueryWrapper<SysEntityInfo> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(SysEntityInfo::getSystemNo, systemNo);
		List<SysEntityInfo> list = list(queryWrapper);
		List<String> entitys = new ArrayList<String>();
		if(list!=null && list.size()>0) {
			for(SysEntityInfo e : list) {
				entitys.add(e.getEntityClassName());
			}
			LambdaQueryWrapper<SysEntityField> fieldQueryWrapper = new LambdaQueryWrapper<>();
			fieldQueryWrapper.in(SysEntityField::getEntityClassName, entitys);
			iSysEntityFieldService.remove(fieldQueryWrapper);
			remove(queryWrapper);
		}
	}

}
